//
//  ZCBHomeController.m
//  ZPHome
//
//  Created by apple on 2017/4/11.
//  Copyright © 2017年 ttayaa. All rights reserved.
//

#import "ZCBHomeController.h"

#import "ZCBHomeBar.h"
#import "ZCBHomeHeadView.h"
#import "ZCBHomeDownMenuController.h"

#import "TTAlertView.h"


//#import "EMChooseViewController.h"
//#import "TTChatController.h"

@interface ZCBHomeController ()<UIAlertViewDelegate>

/** <#what is this#>*/
@property (weak, nonatomic) ZCBHomeBar *HomeBar;

@property (weak, nonatomic) ZCBHomeHeadView *HomeHeadView;

/** 快速建群时选择的好友数组*/
@property (weak, nonatomic) NSArray *friendArr;

///** 动态数据*/
//@property (strong, nonatomic) BSSCModel *dataModel;

///** <#what is this#>*/
//@property (assign,nonatomic) BOOL isUpDate;


@end


@implementation ZCBHomeController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    White_StatusBar;
    
    [self TTNVDefaultBarWithImg:[UIImage imageNamed:@"Nbar"]];
    
    
//    
//    self.isOpenAOP = YES;
//    
//    [self loadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];


    [self scrollViewDidScroll:self.tableView];
    
    self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    self.extendedLayoutIncludesOpaqueBars = YES;
    
//      self.dy_ZCBGIFisRefresh = YES;
}


//ZCBRefreshOrPull
//{
//    [self ZCBendLoading];
//    [self loadData];
//}

//- (void)loadData{
//    weakify(self)
//    [BSSCModel POSTResultWithPath:@"m=Api&c=Index&a=getAllcost" Params:^(BSSCParms *ParmsModel) {
//        
//    } success:^(BSSCModel *model, NSMutableArray<BSSCModel *> *modelArr, id responseObject) {
//        normalize(self)
//        
//      
//        self.dataModel = model;
//        
//        self.isUpDate = YES;
//        
//        /*
//         @property (weak, nonatomic) IBOutlet UILabel *yesterdayLove_lb;
//         @property (weak, nonatomic) IBOutlet UILabel *yesterdayDongli_lb;
//         @property (weak, nonatomic) IBOutlet UILabel *yesterdayaliveLove_lb;
//         @property (weak, nonatomic) IBOutlet UILabel *yesterdayExpenditure_lb;*/
//        
//        self.HomeHeadView.yesterdayLove_lb.text = model.alllove;
//         self.HomeHeadView.yesterdayPower_lb.text = model.allpower;
//         self.HomeHeadView.yesterdayaliveLove_lb.text = model.allloveactive;
//         self.HomeHeadView.yesterdayExpenditure_lb.text =[NSString stringWithFormat:@"%@元",model.allcost] ;
//        
//        self.HomeHeadView.lei_ji_bu_tie_lb.text = model.allsubsidy ;
//        self.HomeHeadView.yong_hu_lb.text = model.users ;
//        self.HomeHeadView.shang_jia_lb.text = model.sellers ;
//        
//        
//        
//    } failure:^(NSError *error) {
//        
//    }];
//    
//}



-(void)initUI
{
    
    //导航条
    ZCBHomeBar *HomeBar = [ZCBHomeBar ViewFromXib];
    
    self.HomeBar = HomeBar;
    
    HomeBar.leftbar_FreindList_btn.clickSignalRespondToController = self;
    HomeBar.leftbar_FreindList_btn1.clickSignalRespondToController = self;
    HomeBar.rightbar_ext_btn.clickSignalRespondToController = self;
    HomeBar.rightbar_ext_btn1.clickSignalRespondToController = self;
    HomeBar.bar_scan_btn.clickSignalRespondToController = self;
    HomeBar.bar_get_btn.clickSignalRespondToController = self;
    HomeBar.bar_pay_btn.clickSignalRespondToController = self;
    
    HomeBar.leftbar_FreindList_btn.clickSignalName = @"FreindList_btn";
    HomeBar.leftbar_FreindList_btn1.clickSignalName = @"FreindList_btn";
    HomeBar.rightbar_ext_btn.clickSignalName = @"ext_btn";
    HomeBar.rightbar_ext_btn1.clickSignalName = @"ext_btn";
  
    HomeBar.bar_scan_btn.clickSignalName = @"scan_btn";
    HomeBar.bar_get_btn.clickSignalName = @"getMoney_btn";
    HomeBar.bar_pay_btn.clickSignalName = @"payMoney_btn";
    
    
    HomeBar.TTwidth = hScreenWidth+100;
    HomeBar.TTheight = 50;
    
    [self.navigationItem setTitleView:HomeBar];
    
    ZCBHomeHeadView *headview =  [ZCBHomeHeadView ViewFromXib];
    headview.AutoWidth = hScreenWidth;
    self.HomeHeadView = headview;
//    self.tableView.TTtableHeaderView = headview;
    self.tableView.tableHeaderView = headview;
    self.tableView.tableFooterView = [UIView new];
    

}



-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = scrollView.contentOffset.y;
    CGFloat alpha = 0;
    
    CGFloat changeheight = self.HomeHeadView.HeadTopBG.TTheight - 64;
    
    //设置bar按钮变化
    if (offsetY >= changeheight) {
        
        alpha=((offsetY-changeheight)/changeheight <= 1.0 ? (offsetY-changeheight)/changeheight:1);
        
        self.HomeBar.titleBarview.hidden = YES;
        self.HomeBar.BarView2.hidden = NO;

    }else{

        self.HomeBar.titleBarview.hidden = NO;
        self.HomeBar.BarView2.hidden = YES;
    }
    
    //设置背景变化
    if (offsetY < 0)
    {
//        self.view.backgroundColor = [UIColor tt_colorWithMacHexString:@"#009BF2"];
        
        self.view.backgroundColor = TTWhiteColor;
    }
    else
    {
        self.view.backgroundColor = self.HomeHeadView.backgroundColor;
    }
    
}



Click_signal(FreindList_btn)
{

    [self.navigationController WillPushViewController:@"TTFriendListController"  animated:YES SetupParms:^(UIViewController *vc, NSMutableDictionary *dict) {
        
        [dict addEntriesFromDictionary:@{
                                         @"isReturnMobile":@"0",
                                         @"isTransferList":@"0",
                                         }];
        
    } callback:^(id parameter) {
        
    }];
    
}
#pragma mark - ---- 右上角 + 按钮 ----
Click_signal(ext_btn)
{
//    if ([BSSCAppUser shareBSSCAppUser].mobile.length<10) {
//        CommonProgressError(@"请先登录")
//        return;
//    }
    
    
    ZCBHomeDownMenuController *downMenuVc = [ZCBHomeDownMenuController new];
    
    [self presentViewController:downMenuVc animated:YES frame:[ZCBHomeDownMenuController getShowFrame] hudColor:TTRGBA32Color(0, 0, 0, 0.2) whenDisplay:^(UIView *toView, id<UIViewControllerContextTransitioning> transitionContext) {
        
        toView.transform = CGAffineTransformMakeScale(0.2, 0.2);
        toView.layer.anchorPoint = CGPointMake(0.9, 0);
        toView.alpha = 0.2;
        [UIView animateWithDuration:0.2 animations:^{
            toView.transform = CGAffineTransformMakeScale(1, 1);
            toView.alpha = 1;
            
        } completion:^(BOOL finished) {
            toView.transform = CGAffineTransformIdentity;
            
            [transitionContext completeTransition:YES];

        }];
        
    } whenDismiss:^(UIView *fromView, id<UIViewControllerContextTransitioning> transitionContext) {
        
        fromView.transform = CGAffineTransformMakeScale(1, 1);

        [UIView animateWithDuration:0.2 animations:^{
            fromView.transform = CGAffineTransformMakeScale(0.5, 0.5);
            fromView.alpha = 0;
        } completion:^(BOOL finished) {
            
            [transitionContext completeTransition:YES];

        }];
        
    } completion:nil];
    
    
    
    
    weakify(self)
    [downMenuVc WhenViewDidDisappear_offen:^(id args) {
        normalize(self)
        if ([args isEqualToString:@"chooseAddFriend"]) {
            UIViewController *addController = [[NSClassFromString(@"AddFriendViewController") alloc] initWithStyle:UITableViewStylePlain];
            [self.navigationController pushViewController:addController animated:YES];
        }
        if ([args isEqualToString:@"chooseAddGroup"]) {
            
            UIViewController *ContactSelectionController = [NSClassFromString(@"ContactSelectionViewController") new];
            if ([ContactSelectionController respondsToSelector:@selector(setDelegate:)]) {
                [ContactSelectionController performSelector:@selector(setDelegate:) withObject:self];
            }
            [self.navigationController pushViewController:ContactSelectionController animated:YES];
        }
        if ([args isEqualToString:@"chooseScan"])
        {//扫一扫
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"TTQRScan" bundle:nil];
            
            UIViewController * vc = [sb instantiateViewControllerWithIdentifier:@"TTQRScanController"];
            [self.navigationController pushViewController:vc animated:YES];
        }
        if ([args isEqualToString:@"choosegetMoney"])
        {//我的二维码
            
          [self.navigationController WillPushViewController:@"ZCBGetMoneyQRCodeContoller" animated:YES SetupParms:nil callback:nil];
        }
        
        
    }];

    
    
    
}


#pragma mark -  扫一扫
Click_signal(scan_btn)
{

    
//    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"TTQRScan" bundle:nil];
//
//    UIViewController * vc = [sb instantiateViewControllerWithIdentifier:@"TTQRScanController"];
//
//    [self.navigationController pushViewController:vc animated:YES];
    
}

#pragma mark -  收款
Click_signal(getMoney_btn)
{

    
    
    [self.navigationController WillPushViewController:@"ZCBGetMoneyQRCodeContoller" animated:YES SetupParms:nil callback:nil];

}

#pragma mark -  付款
Click_signal(payMoney_btn)
{
   
    
    [TTAlertView showOneButtonWithTitle:@"提示信息" Message:@"该功能暂未开放!" ButtonType:TTAlertViewButtonTypeNone ButtonTitle:@"确定" Click:^{
        
    }];
//     [self.navigationController WillPushViewController:@"TTPaytoStoreController" animated:YES SetupParms:nil callback:nil];
//    
 
}

#pragma mark - //转账
Click_signal(transfer_btn)
{

    
    [self.navigationController WillPushViewController:@"ZCBTransferListController" animated:YES SetupParms:nil callback:nil];

    
    
}

#pragma mark - //手机充值
Click_signal(Phone_Recharge_btn)
{


     [self.navigationController WillPushViewController:@"FSCHFCZPageController" animated:YES SetupParms:nil callback:nil];
    
}
#pragma mark - //油卡充值
Click_signal(CarOil_Recharge_btn)
{

}

#pragma mark - 生活缴费
Click_signal(lifepay_btn)
{
  
    
    [TTAlertView showOneButtonWithTitle:@"提示信息" Message:@"该功能暂未开放!" ButtonType:TTAlertViewButtonTypeNone ButtonTitle:@"确定" Click:^{
        
    }];

}
#pragma mark - 月供宝
Click_signal(repay_btn)
{

    
    [self.navigationController WillPushViewController:@"ZCBMonthPayController" animated:YES SetupParms:nil callback:nil];

}

#pragma mark - 商城
Click_signal(store_btn)
{
    

    [self presentViewController:[NSClassFromString(@"ZCBBSSCMainController") new] animated:YES completion:nil];

}


#pragma mark - 汽车
Click_signal(cart_btn)
{
ttLog(@"cart_btn");
}

Click_signal(more_btn)
{

    
    [self.navigationController WillPushViewController:@"ZCBMorePlateController" animated:YES SetupParms:nil callback:nil];

    
    
}



#pragma mark - ---- 精选动态 ----
Click_signal(ChoicenessDynamic_view)
{
ttLog(@"精选动态");
    
}

#pragma mark - ---- 昨日爱心 ----
Click_signal(ZRAX_view)
{

    [self.navigationController WillPushViewController:@"ZCBYesterdayLoveValueController" animated:YES SetupParms:nil callback:nil];

}

@end
